// 任务下发模块

import { observer } from "mobx-react";
import "./index.less"
import { Card, Spin, Button, Row, Col, Form, Input, Divider, Descriptions, Table } from 'antd';
import { PlayCircleOutlined } from '@ant-design/icons';
import store from "./model.ts"
import Menu from "../publicComponent/menu/index.jsx"
import { history } from "umi";
import Scan from "../publicComponent/scan"
import { useEffect, useState } from "react";
import indexStore from "../model"
import { sys } from "@/utils/sys";
import FingerApi from "../finger_device/model";
import allocationStore from "../Allocation/model"
const nw = require('nw.gui');



function Index() {

    let [list, setList] = useState([])
    let [name, setName] = useState("")
    let [isfinger, setIsfinger] = useState(true)


    // 5s关闭弹框
    setTimeout(() => {
        const win = nw.Window.get();
        win.close();
    }, 5000);

    // 设置nw弹框背景透明
    useEffect(() => {
        let win = nw.Window.get()
        win.window.document.body.style.backgroundColor = 'transparent'
    }, [])

    // 拿到传过来的数据
    useEffect(() => {
        let data = sys.urlToJsonData()
        if (data.data.isfinger === "没有录入指纹") {
            setIsfinger(false)
        }
        setName(data.data.name)
        setList(data.data.list)
    }, [])

    // 记录最后一次跳转路由path
    // 设置窗口大小和位置
    useEffect(() => {
        FingerApi.centerWindow()
    }, [])


    // 处方表头
    let columns = [
        {
            title: '序号',
            dataIndex: 'index',
            align: "center",
            width: 55
        },
        {
            title: '处方名',
            dataIndex: 'planName',
            align: "center"
        },
        {
            title: '诊疗技术',
            dataIndex: 'technology',
            align: "center"
        },
        {
            title: '诊疗次数',
            dataIndex: 'numberOfTimes',
            align: "center"
        },
        {
            title: '开发时间',
            dataIndex: 'createTime',
            align: "center"
        },
        {
            title: '医师',
            dataIndex: 'createUser',
            align: "center"
        },
        // {
        //     title: '是否已完成',
        //     align: "center",
        //     render: function() {
        //         return(
        //             <span>
        //                 <a>已完成</a>
        //             </span>
        //         )
        //     }
        // },
    ]

    return (
        <>

            <div className="popup">
                {
                    isfinger
                        ?
                        (list.length
                            ?
                            <>
                                <div>{name}您好!</div>
                                您的处方已下发到当前设备
                            </>
                            :
                            <>
                                <div style={{ color: "red" }}>{name}您好!</div>
                                <div style={{ color: "red" }}>您当前没有处方</div>
                            </>
                        )
                        : <div style={{ color: "red" }}>您没有录入指纹</div>
                }

                <div className="popup-body">
                    {/* <Button onClick={() => {
                        const nw = require('nw.gui')
                        const win = nw.Window.get()
                        win.close()
                    }}>关闭</Button>
                    <Button
                        onClick={() => {
                            let str = localStorage.getItem("endPath")
                            console.log("本地存储", str)
                            let store = allocationStore.patientInfo
                            console.log("store", store)
                        }}
                    >按钮---{allocationStore.patientInfo.name}</Button> */}
                    {/* <div className="popup-body-detail">
                        <Divider style={{ fontSize: "25px" }} children={`${name}您好`} />
                        <Table
                            bordered
                            pagination={false}
                            rowKey="id"
                            size="small"
                            columns={columns}
                            dataSource={prescriptionList}
                        />
                    </div> */}
                </div>
            </div >

        </>
    )
}

export default observer(Index)